const cloud = require("wx-server-sdk");

cloud.init({ env: process.env.WX_CLOUD_ENV || cloud.DYNAMIC_CURRENT_ENV });

/**
 * login 云函数：返回用户 openid、appid、unionid
 * 用于客户端快捷登录凭据获取
 */
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext();
  return {
    openid: wxContext.OPENID,
    appid: wxContext.APPID,
    unionid: wxContext.UNIONID || "",
  };
};
